package com.zhengtoudai.ui.activity;

import android.os.Bundle;
import android.text.InputFilter;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.zhengtoudai.R;
import com.zhengtoudai.base.App;
import com.zhengtoudai.base.BaseActivity;
import com.zhengtoudai.global.Config;
import com.zhengtoudai.http.HttpUtil;
import com.zhengtoudai.injector.component.DaggerActivityComponent;
import com.zhengtoudai.injector.module.ActivityModule;
import com.zhengtoudai.ui.presenter.ShengTenpayPresenterImpl;
import com.zhengtoudai.ui.view.ShengTenpeyView;
import com.zhengtoudai.util.CashierInputFilter;
import com.zhengtoudai.util.Tool;

import java.util.HashMap;
import java.util.Map;

import javax.inject.Inject;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class RechargeActivity extends BaseActivity implements ShengTenpeyView{

    /*@Bind(R.id.tv_channel)
    TextView mTvChannel;*/
    @Bind(R.id.edt_recharge_money)
    EditText mEdtRechargeMoney;
    /*@Bind(R.id.tv_balance)
    TextView mTvBalance;*/

    @Inject
    ShengTenpayPresenterImpl mPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recharge);
        ButterKnife.bind(this);
    }

    @Override
    protected void initTitle() {
        titleUtil.setTitle("充值");
    }

    @Override
    protected void initView() {
        mEdtRechargeMoney.setFilters(new InputFilter[]{new CashierInputFilter()});
        DaggerActivityComponent.builder().appComponent(App.mApp.getAppComponent())
                .activityModule(new ActivityModule(this))
                .build().inject(this);
        mPresenter.attachView(this);

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mPresenter.detachView();
    }

    @OnClick({ R.id.btn_recharge})
    public void onClick(View view) {
        if (Tool.isFastDoubleClick()) return;
        switch (view.getId()) {
            case R.id.btn_recharge:
                mEdtRechargeMoney.setError(null);
                String rechargeMoney=mEdtRechargeMoney.getText().toString();
                if (TextUtils.isEmpty(rechargeMoney)||Double.parseDouble(rechargeMoney)==0){
                    mEdtRechargeMoney.setError("请输入充值金额");
                }else{
                    Map<String,String> params=new HashMap<>();
                    params.put("payMoney",rechargeMoney);
                    mPresenter.postShengTenpay(Config.BASE_URL+"appAccountCorrelation/tgRecharge.app",params);
                }
                break;
        }
    }

    @Override
    public void showDialog() {
        showProgressDialog("正在加载中...");
    }

    @Override
    public void onFailure(Throwable e) {
        HttpUtil.disposeOnFailure(this,e);
    }

    @Override
    public void onResult(String html) {
        Bundle bundle=new Bundle();
        bundle.putString("title","盛付通");
        bundle.putString("html",html);
        startActivity(bundle,WebViewActivity.class);
    }

    @Override
    public void dismissDialog() {
        dismissProgressDialog();
    }
}
